package com.example.demo.web;

import com.example.demo.bean.Result;
import com.example.demo.dao.SysUserMapper;
import com.example.demo.domain.SysUser;
import com.example.demo.exception.ServiceException;
import com.example.demo.util.ResHelper;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by ZhaoYuJie on 2018/7/2.
 */
@RestController
@RequestMapping(value = "/user",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "用户操作接口")
public class UserCtrl {
    @Autowired
    private SysUserMapper sysUserMapper;

    @GetMapping("/query")
    @ApiOperation(value = "获取系统用户详细信息",notes = "根据用户id查询系统用户详细信息")
    @ApiResponses({
            @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 1, message = "操作失败")
    })
    public Result<SysUser> query(@ApiParam(value = "用户ID",required = true)@RequestParam long id){
        SysUser sysUser = sysUserMapper.selectByPrimaryKey(id);
        if(sysUser == null){
            throw new ServiceException("查不到该系统用户啊啊啊啊");
        }

        return ResHelper.success(sysUser);
    }


}
